package com.uspacex.calculate.controller;

import com.alibaba.fastjson.JSONObject;
import com.singularsys.jep.functions.Str;
import com.uspacex.calculate.mapper.AnalysisMapper;
import com.uspacex.calculate.service.AnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

@Controller
@RequestMapping("/analysis")
public class AnalysisController {

    @Autowired
    AnalysisService analysisService;
    @Autowired
    AnalysisMapper analysisMapper;

    @RequestMapping(value = "/datelist", produces = {"application/json;charset=UTF-8"}, method = RequestMethod.POST)
    @ResponseBody
    List<String> getDateList(@RequestBody String str) {
        Map<String, Object> resquestParams = JSONObject.parseObject(str, Map.class);
        String enterpriseName = (String) resquestParams.get("enterpriseName");

        Map<String, Object> map = new HashMap<>();
        List<LinkedHashMap<String, Object>> dateInfo = analysisMapper.dateInfo();
        List<String> dateList = new ArrayList<>();
        for (LinkedHashMap date : dateInfo) {
            dateList.add((String)date.get("date_info"));
        }
        return dateList;
    }

    @RequestMapping(value = "/model", produces = {"application/json;charset=UTF-8"}, method = RequestMethod.POST)
    @ResponseBody
    Map<String, Object> getEnterpriseList(@RequestBody String str) {
        Map<String, Object> resquestParams = JSONObject.parseObject(str, Map.class);
        Map<String, Object> map = new HashMap<>();
        String model = (String) resquestParams.get("model");
        String date = (String) resquestParams.get("date");
        /* 1杜邦分析法 2黑色倒闭模型 3沃尔比重分析 4加权打分模型 */
        if (model.equals("1")) {
            map.put("result", analysisService.dubangfenxifa(date));
        } else if (model.equals("2")){
            map.put("result", analysisService.heisedaobimoxing(date));
        } else if (model.equals("3")){
            map.put("result", analysisService.woerbizhongfenxi(date));
        } else if (model.equals("4")){
            map.put("result", analysisService.jiaquandafen(date));
        } else {
            map.put("result", null);
        }

        return map;
    }

}
